/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pasta;

import java.io.*;
import java.util.Vector;

/**
 *
 * @author Junior
 */
public class Splitter {

    public Vector<byte[]> takeInput(String path, int splitLength) throws IOException {

        Vector<byte[]> bytes = new Vector<byte[]>();

        try {

            //path = storageDirectory + "/" + path + ".pdf";

            int c = 0;
            int length = 0;

            File file = new File(path);
            int size = (int)file.length();

            FileInputStream inputFile = new FileInputStream (path);

            c = inputFile.read();

            while (c != -1) {

               byte [] outputByte = null;

               if(size > splitLength){
                   outputByte = new byte[splitLength];
                   size -= splitLength;
               } else {
                   splitLength = size;
                   outputByte = new byte[splitLength];
               }

               while(length < splitLength) {
                    outputByte[length] = (byte)c;
                    c = inputFile.read ();
                    length++;
               }

               length = 0;
               bytes.add(outputByte);
            }
        } catch (NumberFormatException e) {
            System.out.println("Problem in number format...");
            e.printStackTrace();
        }
        return bytes;
    }
}
